      </div>
      </div>
    </div>
<div class="modal fade" id="bs_alert" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title"></h4>
      </div>
      <div class="modal-body"></div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" id="bs_alert_cancel">取消</button>
        <button type="button" class="btn btn-primary" id="bs_alert_sure">确定</button>
      </div>
    </div>
  </div>
</div>
<?php foreach($js as $item=>$key):?>
  <script type="text/javascript" src="<?=$item?>"></script>
<?php endforeach;?>
<script type="text/javascript">

function passwordChange(){
  var html = '<form id="location_form">';
  html+=makeInput({name:'password',label:'密码',value:'',type:'password'});
  html+=makeInput({name:'password_new',label:'新密码',value:'',type:'password'});
  html+=makeInput({name:'password_repeat',label:'重复新密码',value:'',type:'password'});
  html+='</form>';
  layer.open({
    title:'修改密码',
    area: ['520px'], //宽高
    content: html,
    btn:['确定','取消'],
    yes:function(index){
      layer.close(index);
      var loading = layer.load(1, {
        shade: [0.5,'#000']
      });
      $.post('<?php echo site_url('admin/login/passwordchange');?>',$("#location_form").serialize(),function(result){
        layer.close(loading);
        if(result.statu=='ok'){
          location.reload();
        }else{
          layer.msg(result.message, {icon: 2});
        }
      },'json')
    }
  });
}
function nameChange(){
  var html = '<form id="location_form">';
  html+=makeInput({name:'name',label:'用户名',value:'<?php echo $user['name'];?>'});
  html+='</form>';
  layer.open({
    title:'修改用户名',
    area: ['520px'], //宽高
    content: html,
    btn:['确定','取消'],
    yes:function(index){
      layer.close(index);
      var loading = layer.load(1, {
        shade: [0.5,'#000']
      });
      $.post('<?php echo site_url('admin/login/namechange');?>',$("#location_form").serialize(),function(result){
        layer.close(loading);
        if(result.statu=='ok'){
          layer.msg(result.message, {icon: 1});
        }else{
          layer.msg(result.message, {icon: 2});
        }
      },'json')
    }
  });
}
function makeInput(config){//type value name label
  if(!config.type) config.type='text';
  var inputStr = '<div class="form-group">';
  inputStr+='<label class="control-label" for="alert_form_'+config.name+'">'+config.label+'</label>';
  if(config.type=='select'){
    inputStr+='<select class="form-control" name="'+config.name+'" id="alert_form_'+config.name+'">';
    if(!config.option) config.option=[];
    $.each(config.option,function(k,v){
      var selected = v.id==config.value?' selected':'';
      inputStr+='<option value="'+v.id+'"'+selected+'>'+v.name+'</option>'
    })
    inputStr+='</select>';
  }else{
    inputStr+='<input type="'+config.type+'" class="form-control" name="'+config.name+'" id="alert_form_'+config.name+'" value="'+config.value+'">';
  }
  return inputStr+'</div>';
}
$.fn.formTip = function(message,type,offset){
  if(typeof(offset)=='undefined') offset=true;
  var $group = $(this).parents('.form-group');
  if($group.length!=1) return;
  var old_type = $group.attr('type');
  if(old_type) $group.removeClass("has-"+old_type);
  $group.attr('type','').children('.help-block').remove();
  if(message&&type){
    var offsetClass = offset?' col-sm-offset-2':'';
    $group.addClass("has-"+type).append('<span class="help-block'+offsetClass+'">'+message+'</span>').attr('type',type);
  }
}
/*
       自定义jquery函数，完成将form 数据转换为 json格式 
*/
$.fn.serializeJson=function(){ 
        var serializeObj={}; 
        var array=this.serializeArray(); 
        // var str=this.serialize(); 
        $(array).each(function(){ // 遍历数组的每个元素 
                if(serializeObj[this.name]){ // 判断对象中是否已经存在 name，如果存在name 
                      if($.isArray(serializeObj[this.name])){ 
                             serializeObj[this.name].push(this.value); // 追加一个值 hobby : ['音乐','体育'] 
                      }else{ 
                              // 将元素变为 数组 ，hobby : ['音乐','体育'] 
                              serializeObj[this.name]=[serializeObj[this.name],this.value]; 
                      } 
                }else{ 
                        serializeObj[this.name]=this.value; // 如果元素name不存在，添加一个属性 name:value 
                } 
        }); 
        return serializeObj; 
};


$.alert = function(title,content,sure,cancel){
  var modal = $('#bs_alert');
  modal.find('.modal-title').text(title);
  modal.find('.modal-body').html(content);
  modal.modal('show');
  $('#bs_alert_sure').off().on('click',function(){
    sure&&sure(modal);
  })
  if(cancel){
    $('#bs_alert_cancel').show().off().on('click',function(){
      cancel&&cancel(modal);
    })
  }else{
    $('#bs_alert_cancel').hide();
  }
  return modal;
}
</script>
</body>
</html>